<meta charset="utf-8" />
<div class="box box-primary" id="bizConfig">
    <div class="box-body">
	<div class="col-lg-3 col-md-3 col-sm-4">
		<div class="panel panel-default">
			<div class="panel-heading">组织机构</div>
			<div class="panel-body" id="sysOrganizationTreeMenu">
				<km-tree host="baseServer" id="sysOrganizationTree" url="sys/sysOrganization/loadOrganizationTree" param="" chooseType="checkbox" isRightClick="true" onclick="loadSysOrganization"
				addChildNodeName="add" editNodeName="edit" removeNodeName="deleteTree" openNum="4"></km-tree>
			</div>
		</div>
	</div>
	<div class="col-lg-9 col-md-9 col-sm-8">
		<form id="searchForm" role="form" class="form-inline" style="display: none;">
			<div class="box-body">
			</div>
			<button type="button" class="btn btn-info pull-right m-t-n-xs" onclick="search();">
				<strong>查询</strong>
			</button>
		</form>
		 <div class="box">
		<div class="box-body">
			<div class="row">
				<div class="col-md-12">
				    <div class="btn-group " id="sysOrganizationToolbar" role="group">
                                    <km-bt-no label="停用" onclick="cancel();"></km-bt-no>
                                    <km-bt-yes label="启用" onclick="activate();"></km-bt-yes>
                                     <km-bt-add label="人员管理" onclick="assigned();"></km-bt-add>
                                     <km-bt-add label="设置" onclick="configure();"></km-bt-add>
                                      <km-bt-add label="创建岗位" onclick="createPossiotion();"></km-bt-add>
                                     <!-- <km-bt-add label="mappingCode测试" onclick="testMappingCode();"></km-bt-add> -->
                           </div>

					<table id="sysOrganizationTable" data-mobile-responsive="true"></table>
				</div>
			</div>
		</div>
	</div>
</div>
</div>
 <script type="text/javascript">
var jqTableDom=$("#sysOrganizationTable");
$(function() {
	loadSysOrganization();
	});
   function loadSysOrganization(id){
	   var jqFormDom=$("#searchForm");
		var jqToolbarDom=$("#sysOrganizationToolbar");
		if(zfesUtil.isEmpty(id)){
			var url=host_auth+"sys/sysOrganization/loadSysOrganizationList";
		}else{
			var url=host_auth+"sys/sysOrganization/loadSysOrganizationList?parentId="+id;
		}
		var columns=[
						{checkbox:true},
						{field:'name',title:'组织机构名称',width:160,sortable:true},
						{field:'code',title:'组织机构编码',width:160,sortable:true},
						{field:'enabled',title:'是否可用',width:160,formatter:zfesUtil.formatBool},
						{field:'telPhone',title:'联系方式',width:160},
						{field:'address',title:'地址',width:200},
						{field:'description',title:'描述',width:200}
					];
		bstable=zfesBstable.laodTable(jqTableDom,jqFormDom,jqToolbarDom,url,columns);
	}
   
   function add(tid){
	   var data=ZFTree.getTreeNodeById("sysOrganizationTreeMenu",tid);
	   var id=data.id;
	   var url="/view/auth/sysOrganization/sysOrganization.add.html";
	   zfesLayerEditDg.open(url,{"id":id},"组织机构信息编辑",560,function(){ZFTree.refreshTreeAll("sysOrganizationTreeMenu");}); 
   }
   
   function createPossiotion(){
	   if(zfesBstable.isOneRow(jqTableDom)){
			var row = zfesBstable.getSelections(jqTableDom);
			 if(row[0].enabled=='0'){
						alertSwal.warningTitle("该组织结构已经是停用状态");
						 return false;
					 }
			 var id=zfesBstable.getRowId(jqTableDom);
			  var url="/view/auth/sysOrganization/sysOrganization.addSysPosition.html";
			    zfesLayerEditDg.open(url,{"id":id},"岗位信息编辑",400,function(){zfesBstable.refresh(jqTableDom);}); 
			 
		   
	   }
   }
   
   
   function cancel(){
	   if(zfesBstable.isOneRow(jqTableDom)){
			var row = zfesBstable.getSelections(jqTableDom);
			 if(row[0].enabled=='0'){
						alertSwal.warningTitle("该组织结构已经是停用状态");
						 return false;
					 }
			var id=zfesBstable.getRowId(jqTableDom);
			var enabled="0";
			 alertSwal.confirm("注销","是否注销该组织机构",function(){
			       layer.close(layer.index);
				 	var ajaxUrl = host_auth+"sys/sysOrganization/updateOrganizationStatus";
					var param = { "id" : id,"enabled":enabled};
					zfesAjax.ajaxTodo(ajaxUrl, param, function(data) {
						alertSwal.successText(data.message);
		 			layer.close(layer.index);
		 			zfesBstable.refresh(jqTableDom);
					}); 
		});
			}
	   
   }
   function activate (){
	   if(zfesBstable.isOneRow(jqTableDom)){
			var row = zfesBstable.getSelections(jqTableDom);
			 if(row[0].enabled=='1'){
						alertSwal.warningTitle("该组织机构已经为启用状态");
						 return false;
					 }
			 var id=zfesBstable.getRowId(jqTableDom);
			 var enabled="1";
			 alertSwal.confirm("启用","是否启用该组织机构",function(){
			       layer.close(layer.index);
				 	var ajaxUrl = host_auth+"sys/sysOrganization/updateOrganizationStatus";
					var param = { "id" : id,"enabled":enabled};
					zfesAjax.ajaxTodo(ajaxUrl, param, function(data) {
						alertSwal.successText(data.message);
		 			layer.close(layer.index);
		 			zfesBstable.refresh(jqTableDom);
				}); 
		});
	   }
   }
   
   function edit(tid){
	   var data=ZFTree.getTreeNodeById("sysOrganizationTreeMenu",tid);
	   var id=data.id;
	   var url="/view/auth/sysOrganization/sysOrganization.edit.html";
	   zfesLayerEditDg.open(url,{"id":id},"组织机构信息编辑",560,function(){ZFTree.refreshTreeSelectNode("sysOrganizationTreeMenu");}); 
   }
   
   function deleteTree(trid){
	   var data=ZFTree.getTreeNodeById("sysOrganizationTreeMenu",trid);
	   var id=data.id;
		 alertSwal.confirm("删除","是否删除该组织机构",function(){
		       layer.close(layer.index);
			 	var ajaxUrl = host_auth+"sys/sysOrganization/deletSysOrganization";
				var param = { "id" : id};
				zfesAjax.ajaxTodo(ajaxUrl, param, function(data) {
					alertSwal.successText(data.message);
	 			     layer.close(layer.index);
	 			    ZFTree.refreshTreeSelectNode("sysOrganizationTreeMenu");
				}); 
	});
	   
   }
   
    function assigned(){
	   if(zfesBstable.isOneRow(jqTableDom)){
		   var row = zfesBstable.getSelections(jqTableDom);
		   if(row[0].enable=='0'){
			   alertSwal.warningTitle("该组织机构已经停用，不能进行人员分配");
				 return false;
		   }
		   var url="/view/auth/sysOrganization/sysOrganizationAssign.html";
		   zfesLayerEditDg.open(url,{"id":row[0].uniqueCode},"组织机构信息编辑",1000,function(){zfesBstable.refresh(jqTableDom);}); 
	   }
   } 
    function configure(){
    	if(zfesBstable.isOneRow(jqTableDom)){
    		   var row = zfesBstable.getSelections(jqTableDom);
    		   if(row[0].enable=='0'){
    			   alertSwal.warningTitle("该组织机构已经停用，不能设置组织机构信息");
    				 return false;
    		   }
    		   var id=zfesBstable.getRowId(jqTableDom);
    		   var url=host_auth+"/view/auth/sysOrganization/sysOrganization.configure.html";
    		   zfesLayerEditDg.open(url,{"id":id},"组织机构信息设置",800,function(){zfesBstable.refresh(jqTableDom);}); 
    	}
    }
    
    function testMappingCode (){
 				 	var ajaxUrl = host_auth+"/sys/sysOrganization/testMappingCode";
 					zfesAjax.ajaxTodo(ajaxUrl, {}, function(data) {
 						alertSwal.successText(data.message);
 		 		     	layer.close(layer.index);
 		 			   zfesBstable.refresh(jqTableDom);
 				}); 
 	  
    }
</script> 
</div>
